package main.java.io;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class io1 {
    public static void main(String[] args) throws IOException {
        File f = new File("C:\\Users\\86158\\Desktop\\datax.txt");
        RandomAccessFile ra = new RandomAccessFile(f,"rw");
        FileChannel fc = ra.getChannel();

        //创建buffer
        ByteBuffer bf = ByteBuffer.allocate(1024);

        String input = "abcdefg";

        bf.clear();
        bf.put(input.getBytes());
        bf.flip();

        while (bf.hasRemaining()){
            fc.write(bf);
        }
        fc.close();
    }
}
